using UnityEngine;
using System.Collections;

public class Player : Alive_object {
//	public object_data object_data_;
//	public game_data player_data_;
//	public State[] arr_state_;
//	protected FSM fsm;
	
	public Vector3 Player_Direction = Vector3.zero;
	private GameManager GM = GameManager.getInstance();
	private CollisionManager collision_manager;
//	public Transform Upper_body;
	void Start () {
		try
		{
			player_data_ = new player_data();
			player_data_.SetData( GameObject.Find("GameData").GetComponent<game_data>() );
			collision_manager = CollisionManager.getInstance();
			base.init();
			
		}
		catch
		{
			print("Player script fail");
		}
	}
	
	void Update () {
		fsm.Run_state(this);
		collision_manager.CollisionUpdate();
		
		if( this.player_data_.Player_Dash_Residual_Point < this.player_data_.Player_Dash_Point_Maximum )
		{
			this.player_data_.Player_Dash_Residual_Point += this.player_data_.Player_Dash_Point_Regeneration * Time.deltaTime;
			Transform dash_bar = GM.Dash_Bar.transform;
			dash_bar.localScale = new Vector3((( 130 * this.player_data_.Player_Dash_Residual_Point) / this.player_data_.Player_Dash_Point_Maximum ),20,0);
		}
		else if( this.player_data_.Player_Dash_Residual_Point > this.player_data_.Player_Dash_Point_Maximum )
		{
			this.player_data_.Player_Dash_Residual_Point = this.player_data_.Player_Dash_Point_Maximum;
		}
		GM.Dash_per.text = string.Format("{0}/{1} // {2}%",
											this.player_data_.Player_Dash_Residual_Point,
											this.player_data_.Player_Dash_Point_Maximum,
											(this.player_data_.Player_Dash_Residual_Point/this.player_data_.Player_Dash_Point_Maximum)*100);
	}
	public bool TryDash() {
		if( 0 < player_data_.Player_Dash_Residual_Point)
		{
			fsm.Change_state(this.arr_state_[2],this);
			return true;
		}
		return false;
	}
}